package com.oristartech.netty.server.auto;

import com.oristartech.netty.server.starter.NettyServerStarter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

/**
 ** Netty服务端启动异步运行
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-03-23 10:14
 * @blame Team
 */
@Slf4j
@Configuration
@ConditionalOnProperty(prefix = "netty.server",value = "enabled")
public class NettyServerStarterConfiguration implements ApplicationRunner {

    @Resource
    NettyServerStarter nettyServerStarter;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("netty.server.enabled: true");
        CompletableFuture.runAsync(() -> nettyServerStarter.start());
    }
}
